<template>
  <div class="content-card">
    <div class="title">
      <a-icon type="tags"></a-icon>
      <span>{{ "提供数据部门TOP10" }}</span>
    </div>
    <div class="body">
      <div class="label">
        <img src="@/assets/img/assemble/5-1.jpg" alt="5-1" />
        <img src="@/assets/img/assemble/5-2.jpg" alt="5-2" />
        <img src="@/assets/img/assemble/5-3.jpg" alt="5-3" />
      </div>
      <div class="chart" id="data-assemble__chart5"></div>
    </div>
  </div>
</template>

<script>
import API from "@/api/assemble";

export default {
  name: "a5-chart",
  data() {
    return {
      chartData: null,
    };
  },
  methods: {
    getChartData() {
      let handleV1 = (res) => (
        (this.chartData = res.data.body.data), this.registerAndSetCharts()
      );
      API.getChart5_v1().then(handleV1);
    },
    registerAndSetCharts() {
      let chartsRef = this.$echarts.init(
        document.getElementById("data-assemble__chart5")
      );
      //对数据进行格式化
      var name = [];
      var num = [];
      for (var item in this.chartData) {
        switch (this.chartData[item].table_schema) {
          case "tyq_sscjgj":
            name.push("市市场监管局");
            break;
          case "tyq_sgaj":
            name.push("市公安局");
            break;
          case "tyq_srsj":
            name.push("市人社局");
            break;
          case "tyq_swjw":
            name.push("市卫健委");
            break;
          case "tyq_sfgw":
            name.push("市发改委");
            break;
          case "tyq_szrzyhghj":
            name.push("市自然资源规划局");
            break;
          case "tyq_sgjj":
            name.push("市公积金");
            break;
          case "tyq_szjj":
            name.push("市住建局");
            break;
          case "tyq_smzj":
            name.push("市民政局");
            break;
          case "tyq_sxzspj":
            name.push("市行政审批局");
            break;
        }
        // name.push(this.chartData[item].table_schema);
        num.push(Object.values(this.chartData[item])[1]);
      }

      let option = {
        tooltip: {
          trigger: "axis",
        },
        grid: {
          left: "0",
          right: "5%",
          bottom: "2%",
          top: "2%",
          containLabel: true,
        },
        xAxis: {
          show: false,
        },
        yAxis: {
          type: "category",
          // data: ["xx1", "xx2", "xx3", "工信局", "市场监管", "文旅", "发改委"],
          inverse: true,
          data: name,
          axisLabel: {},
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: {
          type: "bar",
          barWidth: 14,
          // data: [152003, 170489, 180034, 194700, 208213, 262132, 291231],
          data: num,
          showBackground: true,
          backgroundStyle: {
            borderRadius: 5,
            color: "rgba(180, 180, 180, 0.2)",
          },
          itemStyle: {
            borderRadius: 5,
            color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#8CBEFF" },
              { offset: 1, color: "#5F8CC8" },
            ]),
          },
        },
      };
      chartsRef.setOption(option);
    },
  },
  mounted() {
    this.getChartData();
  },
};
</script>

<style lang="less" scoped>
.content-card {
  height: 100%;
  .title {
    display: flex;
    align-items: center;
    padding: 10px 0;
    background: linear-gradient(to right, #dee9ff, #ffffff);
    i {
      color: #6989c6;
      margin: 0 15px;
      font-size: 18px;
    }
    span {
      font-size: 16px;
      font-weight: 500;
    }
  }
  .body {
    width: 100%;
    height: 300px;
    display: flex;
    .label {
      width: 10%;
      padding-top: 2%;
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 19px;
        height: 22px;
        margin: 5px 0;
      }
    }
    .chart {
      width: 90%;
    }
  }
}
</style>
